﻿@model IEnumerable<IGrouping<Guid, IFDB.Models.Tables.AppearanceEvent>>

<table class="AppearancePersonTable">
    @{bool isSubstitute = false;}

    @foreach (var group in Model)
    {
        if (!isSubstitute && group.Take(1).Single().MatchEventType == IFDB.ResourceLibrary.MatchEventType.Substitute)
        {
            <tr>
                <td  class="LeftTeam" colspan="2" style="padding-top: 10px;">
                    <h4>Substitutes</h4>
                </td>
            </tr>
            isSubstitute = true;
        }
        
        <tr>
            <td class="LeftTeam">
                @foreach (var appearance in group)
                {
                    @Html.Partial("~/Views/Shared/Match/_AppearanceImages.cshtml", appearance);
                }
                
                @Html.ActionLink(group.Take(1).Single().Person.Forenames + " " + group.Take(1).Single().Person.Surname, "Index", "Person", new { personId = group.Take(1).Single().PersonId }, null)
            </td>
            <td class="Position">
                @string.Format("({0})", group.Take(1).Single().Person.Position.ToString().Substring(0,1))
            </td>
        </tr>
    }
</table>
